package com.saishi.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Method;

public class BaseServlet extends HttpServlet{
	protected void hello(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		System.out.println("找不到此方法");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
	}



	protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		String url = request.getRequestURI();
		int gang = url.lastIndexOf("/");
		String work = url.substring(gang+1);
		System.out.println(url);
		Method m = null;

		try {
			m = this.getClass().getDeclaredMethod(work,HttpServletRequest.class,HttpServletResponse.class);
			m.invoke(this, request,response);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("找不到此方法");
		}
	}
}